//
//  RootViewController.m
//  PTravel
//
//  Created by dllo on 15/12/5.
//  Copyright © 2015年 李涵. All rights reserved.
//

#import "RootViewController.h"
#import "AppDelegate.h"
@interface RootViewController ()<UIScrollViewDelegate, UIApplicationDelegate>
@property (nonatomic, retain) UIView *blackView;
@property (nonatomic, retain) UIScrollView *scrollView;
@property (nonatomic, retain) UIPageControl *page;
@end

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self subViews];
}
#pragma  mark ** 引导页
- (void)subViews
{
    
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    [self.view addSubview:self.scrollView];
    [self.scrollView release];
    self.scrollView.contentSize = CGSizeMake(self.view.frame.size.width * 3, 0);
    self.scrollView.pagingEnabled = YES;
    self.scrollView.delegate = self;
    
    
    for (int i = 0; i < 3; i++) {
        
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:
                                  CGRectMake(self.view.frame.size.width * i, 0, self.view.frame.size.width, self.view.frame.size.height)];
        [self.scrollView addSubview:imageView];
        
        [imageView release];
        
        imageView.tag = 400 + i;
        imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"about%d.png",i]];
        
        if(i == 0)
        {
            UIView *view = [[UIView alloc] initWithFrame:CGRectMake(10, 50, self.view.frame.size.width - 20, 30)];
            [imageView addSubview:view];
            [view release];
            view.backgroundColor = [UIColor grayColor];
            view.alpha = 0.3;
            
            UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(10, 50, self.view.frame.size.width - 20, 30)];
            [imageView addSubview:title];
            [title release];
            title.text = @"热门推荐,来一场说走就走的旅行";
            title.textColor = [UIColor whiteColor];
            title.font = [UIFont boldSystemFontOfSize:20];
            title.textAlignment = NSTextAlignmentCenter;
        }
        
        if (i == 1) {
            UIView *view = [[UIView alloc] initWithFrame:CGRectMake(10, 50, self.view.frame.size.width - 20, 30)];
            [imageView addSubview:view];
            [view release];
            view.backgroundColor = [UIColor grayColor];
            view.alpha = 0.3;
            
            UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(10, 50, self.view.frame.size.width - 20, 30)];
            [imageView addSubview:title];
            [title release];
            title.text = @"更多目的地,想去哪里就去哪里";
            title.textColor = [UIColor whiteColor];
            title.font = [UIFont boldSystemFontOfSize:20];
            title.textAlignment = NSTextAlignmentCenter;
        }
        
        if (i == 2) {
            
            UIView *view = [[UIView alloc] initWithFrame:CGRectMake(10, 50, self.view.frame.size.width - 20, 30)];
            [imageView addSubview:view];
            [view release];
            view.backgroundColor = [UIColor grayColor];
            view.alpha = 0.3;
            
            UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(10, 50, self.view.frame.size.width - 20, 30)];
            [imageView addSubview:title];
            [title release];
            title.text = @"人在旅途,看看别人怎么玩";
            title.textColor = [UIColor whiteColor];
            title.font = [UIFont boldSystemFontOfSize:20];
            title.textAlignment = NSTextAlignmentCenter;
            
            UIButton *begin = [UIButton buttonWithType:UIButtonTypeCustom];
            begin.frame = CGRectMake(0, 0, 100, 40);
            begin.center = CGPointMake(self.view.center.x, self.view.frame.size.height - 120);
            [imageView addSubview:begin];
            imageView.userInteractionEnabled = YES;
            
            [begin setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [begin setTitle:@"开始旅途" forState:UIControlStateNormal];
            [begin addTarget:self action:@selector(begin) forControlEvents:UIControlEventTouchUpInside];
            begin.backgroundColor = [UIColor colorWithRed:108 / 255.0 green:108 / 255.0 blue:108 / 255.0 alpha:0.5];
        }
    }
    
    
    self.page = [[UIPageControl alloc] initWithFrame:CGRectMake(0, 0, 70, 30)];
    self.page.backgroundColor = [UIColor colorWithRed:108 / 255.0 green:108 / 255.0 blue:108 / 255.0 alpha:0.4];
    [self.view addSubview:self.page];
    [self.page release];
    self.page.center = CGPointMake(self.view.center.x, self.view.frame.size.height - 50);
    self.page.numberOfPages = 3;
    
}

#pragma  mark ** 结束引导页
- (void)begin
{
    [self.scrollView removeFromSuperview];
    [self.page removeFromSuperview];
    AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    [app tabBarSubview];
}

- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
{
    if (scrollView.contentOffset.x / BOUNDS.size.width > 2) {
        [self.scrollView removeFromSuperview];
        [self.page removeFromSuperview];
        AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
        [app tabBarSubview];

    }
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    self.page.currentPage = scrollView.contentOffset.x / self.view.frame.size.width;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
